import { connect } from 'dva';
import User from "../../components/user/user";
import React from "react";

class UserRoute extends React.Component {

  render() {

    const { dispatch, user } = this.props;
    const { userList, groupList, name, gid } = user;

    const userPros = {
      userList,
      groupList,
      name,
      gid,
      onEdit: (values) => {
          dispatch({
            type: 'user/updateOne',
            payload: values,
          });
      },

      onAdd: (values) => {
        dispatch({
          type: 'user/addOne',
          payload: values,

        });
      },

      onDelete: (values) => {
        dispatch({
          type: 'user/deleteOne',
          payload: values,
        });
      },

      onSearch : (values) => {
        dispatch({
          type: 'user/queryList',
          payload: values,
        })
      },

      onReset : () => {
        dispatch({
          type: 'user/queryList',
        })
      }

    }

    return (
      <div>
       <User {...userPros} />
      </div>
    );
  }
};

function mapStateToProps(state) {
  return {
    user: state.user,
  };
}

export default connect(mapStateToProps)(UserRoute);
